package aplicacio;

import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.config.Configuration;
import com.db4o.query.Predicate;
import domini.Plasa;
import java.util.List;
import library.inout.Terminal;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.B545835B-E880-8A2D-84F7-56FDCC3EA2C9]
// </editor-fold> 
public class CU02 {

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.4FFB872A-CF4A-400C-0F2C-8522668B108B]
    // </editor-fold> 
    private void gestionarCasUs() {
        Terminal.print("\n\nCu01: Eliminar una plaça\n\n");
        Configuration conf = Db4o.configure();
        conf.objectClass("domini.Plasa").cascadeOnDelete(true);
        ObjectContainer objectContainer = Db4o.openFile("parking.yap");
        final int eoid = Terminal.readInt("Eoid de la plaça ? ");
        Predicate<Plasa> predicat = new Predicate<Plasa>() {

            public boolean match(Plasa plaça) {

                boolean cond = plaça.getEoid() == eoid;
                return cond;
            }
        };
        List<Plasa> places = objectContainer.query(predicat);
        if (!places.isEmpty()) {
            Plasa plasaEliminar = places.get(0);
            objectContainer.delete(plasaEliminar);
            Terminal.print("\nLa plaça ha sigut eliminada.\n\n");
        } else {
            Terminal.print("\nLa plaça no ha sigut eliminada doncs no estava passivada.\n\n");
        }
        objectContainer.close();
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.BDDFBE87-F805-0397-9DF7-1F98145633E1]
    // </editor-fold> 
    public static void main(String[] args) {
        CU02 cu = new CU02();
        cu.gestionarCasUs();
    }
}

